<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use app\traits\MyModelTrait;

/**
 * @property int $id
 * @property string $created_at 创建时间
 * @property string $email 邮箱
 * @property string $password 密码
 * @property string $salt 密码盐
 * @property string $updated_at 更新时间
 * @property string $username 用户名
 * @mixin \think\Model
 */
class User extends Model
{
    use MyModelTrait;

    // 表名
    protected $table = 'users';

    /**
     * 生成记录
     *
     * @param string $username  users.username
     * @param string $password  users.password
     * @param string $email     users.email
     */
    public static function generateLog(string $username, string $password, string $email = ''): void
    {
        $salt = self::generateSalt();
        $insert = [
            'username'      => $username,
            'password'      => self::generatePassword($password, $salt),
            'email'         => $email,
            'salt'          => $salt,
            'created_at'    => date('Y-m-d H:i:s'),
            'updated_at'    => date('Y-m-d H:i:s'),
        ];
        self::insert($insert);
    }// generateLog() end
}
